<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>todolist</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        header {
            width: 100%;
            height: 50px;
            line-height: 50px;
            margin: 0 auto;
            color: white;
            background-color: rgb(50, 50, 50);
        }

        #w {
            width: 800px;
            margin: 0 auto;
        }

        header span {
            font-size: 30px;
            vertical-align: middle;
        }

        #input {
            width: 360px;
            height: 30px;
            margin: 0 20px 0 100px;
            padding-left: 15px;
            border-radius: 10px;
            outline: none;
        }

        #btn {
            width: 50px;
            height: 30px;
            vertical-align: middle;
            border-radius: 8px;
        }

        section {
            background-color: #cdcdcd;
        }
    </style>
</head>

<body>
    <header>
        <div id="w">
            <span>toDoList</span>
            <input type="text" placeholder="请输入代办事项" id="input">
            <button id="btn">增加</button>
        </div>
    </header>
    <section id="w">
        <h4>待办事项</h4> 
        <div id="todo">
            <!-- <input type="checkbox"> -->
        </div>
        <h4>已办事项</h4> 
        <div id="done">
        </div>

    </section>




    <script>
        let arr = [12,13,14,15,16]
        console.log(arr.some((item)=>item==12));
        // 获取节点
        const oBtn = document.getElementById("btn");
        const oInput = document.getElementById("input");
        const oTodo = document.getElementById("todo");
        const oDone = document.getElementById("done");

        // 添加点击事件
        let msgArr = [];
        oBtn.onclick = function () {
            // 使用数组对象存储oInput的value值
            console.log(msgArr);
            // 判断输入的内容是否合法 空格或输入的内容重复 进行提示
            let flag = msgArr.some(item=>item.text==oInput.value);
            if(flag){
                alert("您输入的事项已存在");
                return false;
            }
            msgArr.push({
                text:oInput.value,
                btn:false,
            });
            // 渲染到页面
            render(msgArr);
        }
        function render(msgArr){
            for(let i=0;i<msgArr.length;i++){
                let oDiv= document.createElement("div");
                oDiv.innerText=msgArr[i].text;
                oTodo.appendChild(oDiv);
            }
        }

    </script>
</body>

</html>